package com.hand.cloud.b2b.cockpits.cscockpit.widgets.renderers;

import org.springframework.beans.factory.annotation.Autowired;
import org.zkoss.zk.ui.api.HtmlBasedComponent;
import org.zkoss.zul.Div;
import org.zkoss.zul.Label;

import com.hand.cloud.b2b.services.OrderService;

import de.hybris.platform.cockpit.events.CockpitEventAcceptor;
import de.hybris.platform.cockpit.session.UISessionUtils;
import de.hybris.platform.cockpit.widgets.Widget;
import de.hybris.platform.cscockpit.session.impl.OrderedConfigurableBrowserArea;
import de.hybris.platform.cscockpit.utils.CssUtils;
import de.hybris.platform.cscockpit.utils.LabelUtils;
import de.hybris.platform.cscockpit.widgets.controllers.CallContextController;
import de.hybris.platform.cscockpit.widgets.models.impl.CallContextWidgetModel;
import de.hybris.platform.cscockpit.widgets.renderers.impl.CallContextWidgetRenderer;

/**
 * [1].去掉票证和货币部分
 * 
 * @author StephenWang
 */
public class HandCallContextWidgetRenderer extends CallContextWidgetRenderer {

	@Autowired
	private OrderService orderService;

	@Override
	protected HtmlBasedComponent createContentInternal(
			final Widget<CallContextWidgetModel, CallContextController> widget,
			final HtmlBasedComponent rootContainer) {
		final CockpitEventAcceptor addressNotificationEventAcceptor = createAddressNotificationEventAcceptor(widget);
		final OrderedConfigurableBrowserArea browserArea = (OrderedConfigurableBrowserArea) UISessionUtils
				.getCurrentSession().getCurrentPerspective().getBrowserArea();
		browserArea.addNotificationListener(widget.getWidgetCode(),
				addressNotificationEventAcceptor);

		final Div content = new Div();

		content.appendChild(createSiteContent(widget));
		content.appendChild(createCustomerContent(widget));
		// 临时订单创建界面
		content.appendChild(createOrderContent(widget));
		// 去掉票证部分
		// content.appendChild(createTicketContent(widget));
		// 去掉货币部分
		// content.appendChild(createCurrencyContent(widget));
		content.appendChild(createEndCallContent(widget));

		return content;
	}

	/**
	 * 创建临时订单处理界面
	 */
	protected HtmlBasedComponent createOrderContent(
			final Widget<CallContextWidgetModel, CallContextController> widget) {

		final Div container = new Div();
		container.setSclass(CssUtils.combine(new String[] {
				"csCallContextContainer", "csCallContextOrder" }));

		// 订单创建窗口
		final Div projectInfoContainer = new Div();
		projectInfoContainer.setSclass(CssUtils.combine(new String[] {
				"csCustomerInfoContainer", "csInfoContainer" }));
		projectInfoContainer.setParent(container);

		final Label projectLabel = new Label(LabelUtils.getLabel(widget,
				"hasProjectOrder", new Object[0]));
		projectLabel.setSclass(CssUtils.combine(new String[] { "projectLabel",
				"infoLabel" }));
		projectLabel.setParent(projectInfoContainer);

//		Button btn = new Button("点击");
//
//		btn.setParent(projectInfoContainer);

		try {
			this.orderService.createOrder();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return container;
	}

}
